package com.xywl.escort.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xywl.escort.R;
import com.xywl.escort.bean.ShoppingCartResp;
import com.xywl.escort.utils.NumberFormatUtils;
import com.xywl.escort.widget.GlideApp;

import java.util.List;

/**
 * Created by 32422 on 2018/5/4.
 */

public class TreasureAdapter extends BaseQuickAdapter<ShoppingCartResp.DataBean, BaseViewHolder> {
    public TreasureAdapter(int layoutResId, @Nullable List<ShoppingCartResp.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShoppingCartResp.DataBean item) {
        ImageView imageCheck = helper.getView(R.id.image_check);
        if (item.isClick) {
            imageCheck.setImageResource(R.mipmap.bazaar_choose);
        } else {
            imageCheck.setImageResource(R.mipmap.bazaar_not_to_choose);
        }
        helper.setText(R.id.text_name, item.spuName);
        Button btnStatus = helper.getView(R.id.btn_status);
        LinearLayout layoutShopSum = helper.getView(R.id.layout_shop_sum);
        LinearLayout linearTreasure = helper.getView(R.id.content);
        if (item.stock > 0 && item.status == 1) {
            linearTreasure.setAlpha(1.0f);
            btnStatus.setVisibility(View.GONE);
            layoutShopSum.setVisibility(View.VISIBLE);
            if (null != item.amount) {
                helper.setText(R.id.tv_amount, String.valueOf(item.amount.intValue()));
            }
        } else {
            linearTreasure.setAlpha(0.5f);
            btnStatus.setVisibility(View.VISIBLE);
            layoutShopSum.setVisibility(View.GONE);
            if (item.stock == 0) {
                btnStatus.setText("已抢光");
            } else if (item.status == 2) {
                btnStatus.setText("已抢光");
            } else if (item.status == 3){
                btnStatus.setText("已下架");
            }
        }

        helper.setText(R.id.text_prompt, item.skuName);
        if (null != item.price) {
            String price = "￥:" + NumberFormatUtils.getInstance().format2Decimal(item.price.doubleValue());
            helper.setText(R.id.text_price, price);
        }
        if (null != item.originalPrice) {
            String originalPrice = "￥:" + NumberFormatUtils.getInstance().format2Decimal(item.originalPrice.doubleValue());
            helper.setText(R.id.text_original_price, originalPrice);
        }
        ImageView imageView = helper.getView(R.id.image_commodity);
        GlideApp.with(mContext)
                .load(item.imageUrl)
                .centerCrop()
                .placeholder(R.mipmap.icon_default_picture)
                .into(imageView);

        helper.addOnClickListener(R.id.image_check);
        helper.addOnClickListener(R.id.image_delete);
        helper.addOnClickListener(R.id.image_increase);
        helper.addOnClickListener(R.id.image_decrease);
        helper.addOnClickListener(R.id.content);
    }
}
